package com.laboratory.servicecustomer.testCode;

import com.Laboratory.util.completionUtil;

import org.junit.jupiter.api.Test;
import com.laboratory.servicecustomer.util.MD5Util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMessage.RecipientType;

/**
 * @Author acok
 * @description:TODO
 * @Date 2022/12/14 10:19
 * @Version 1.0
 */
public class test01 {
    @Test
    public void pa() {

        /* root System.out.println(MD5Util.md5Util("030499", 3, "3a8g"));*/
        System.out.println(MD5Util.md5Util("123321",3,"920c"));
    }
    @Test
    public void getTime() throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long dd = 1000 * 24 * 60 * 60;
        long hh = 1000 * 60 * 60;
        long mm = 1000 * 60;
        long ms = 1000;

        long cut = 0;
        cut = format.parse("2022-12-17 12:30:30").getTime() - format.parse("2022-12-16 12:30:30").getTime();
        System.out.println(cut / dd);
        System.out.println(cut / hh);
        System.out.println(cut / mm);
        System.out.println(cut / ms);
    }
    @Test
    public void test001() throws ParseException {
        String[] arr = {"001", "002", "003", "004", "005", "006", "007", "008", "009", "010", "011", "012", "013", "014", "015", "016", "017", "018", "019", "020"};
        System.out.println(completionUtil.autoCompletionEquipmentNo(arr));
    }
    @Test
    public void getCode() {
        System.out.println(Integer.parseInt("001"));
        System.out.println(UUID.randomUUID().toString().replace("-", "").toUpperCase());
    }
    @Test
    public void getNo() {
        String[] arr = new String[1000];
        int size = 3;
        String s = String.valueOf(arr.length + 1);
        for (int i = 0; i < size; i++) {
            if (s.length() < size) {
                s = '0' + s;
            }
        }
        System.out.println(s);
    }
    @Test
    public void getString() {
        String[] arr = {"056"};
        int size = 3;
        if (arr.length > 0 && arr[0] == "001") {
            int endNum = Integer.parseInt(arr[arr.length - 1]);
            if (endNum != arr.length) {
                for (int i = 0; i < arr.length - 1; i++) {
                    int i1 = Integer.parseInt(arr[i]);
                    int i2 = Integer.parseInt(arr[i + 1]);
                    if (i2 - i1 > 1) {
                        String s = String.valueOf(i1 + 1);
                        for (int j = 0; j < size; j++) {
                            if (s.length() < size) {
                                s = '0' + s;
                            }
                        }
                        System.out.println(s);
                        break;
                    }
                }
            } else {
                String s = String.valueOf(arr.length + 1);
                for (int i = 0; i < size; i++) {
                    if (s.length() < size) {
                        s = '0' + s;
                    }
                }
                System.out.println(s);
            }
        } else {
            System.out.println("001");
        }
    }
    @Test
    public void sendEmail() throws MessagingException {
        Properties prop = new Properties();
        prop.setProperty("mail.transport.protocol", "smtp");//定义邮件发送协议
        prop.setProperty("mail.smtp.host", "smtp.qq.com");//声明邮件服务器地址
        prop.setProperty("mail.smtp.auth", "true");//发送权限，为true时表示允许发送
        prop.setProperty("mail.debug", "true");//设置为true时，调试的时候可以在控制台显示信息


        Session session = Session.getInstance(prop);//相当于建立了一条通信路线
        Message msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("3076998511@qq.com"));//发件者邮箱
        msg.setRecipient(RecipientType.TO, new InternetAddress("1810641644@qq.com"));//收件邮箱
        msg.setSubject("这是3076998511发送给1810641644的邮件《测试》");
        msg.setText("测试");

        Transport tran = session.getTransport();
        tran.connect("3076998511", "wrmoqovbehnddhcf");//假设q号为982690136的密码为123456
        tran.sendMessage(msg, msg.getAllRecipients());
    }
    @Test
    public void file() throws IOException {
        /*File file=new File("D:\\LocalServiceFails/1c6a78fc-30ad-4fb5-b43b-bb37d1022c9a.xls");
        FileInputStream fi = new FileInputStream(file);
        HSSFWorkbook wb = new HSSFWorkbook(fi);//xslx
        HSSFSheet sheet= wb.getSheetAt(0); //sheet 从0开始
        System.out.println(sheet.getLastRowNum()+1);
        System.out.println(file.getName());
        System.out.println(file.getPath());*/
        String[] split = "D:\\LocalServiceFails/1c6a78fc-30ad-4fb5-b43b-bb37d1022c9a.xls".split("/");
        System.out.println(split[split.length-1]);
    }
    @Test
    public void fileTest(){
        int count=0;
        File folder = new File("C:\\Users/30769/Desktop/local");
        File[] files=folder.listFiles();
        List<String>fileName=new ArrayList<>();
        fileName.add("a.xlsx");
        fileName.add("b.xlsx");
        if(files!=null){
        for (
            String s:
            fileName) {
            for (File file :
                    files) {
                if (file.getName().equals(s)){
                    count++;
                    file.delete();
                }
            }
        }
            System.out.println(count);
        }

    }
}
